Redis Cookbook by O'reilly Media Incorporated; Tiago Macedo; Fred Oliveria

Redis Cookbook by O'reilly Media Incorporated; Tiago Macedo; Fred Oliveria

Author:O'reilly Media, Incorporated; Tiago Macedo; Fred Oliveria
Language: eng
Format: mobi
Tags: COMPUTERS / General, Computers, General
ISBN: 9781449305048
Publisher: O'Reilly Media
Published: 2011-07-22T04:59:34+00:00


// When we get a message in one of the channels we're subscribed to,

// we send it over to all connected clients.

rc.on("message", function (channel, message) {

console.log("Sending: " + message);

socketio.sockets.emit('message', message);

})

As you can see, our actual Redis code is extremely simple. All we do is listen for messages on a specific channel, and when they arrive, we broadcast them to all clients that are connected to us.

Implementing the client side code

With the server side part completed, all we have to do is create a small page that connects to Node.js, sets up Socket.IO on the client side, and then deals with incoming and outgoing messages. So let’s create a page like that now. Here’s the main trunk for a very simple HTML5 page:

<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Chat with Redis</title>

</head>

<body>

<ul id="messages">

<!-- chat messages go here -->

</ul>

</body>

</html>

Now we need to include the two main pieces we need to get the functionality working: jQuery and Socket.IO. We’ll grab the first from Google’s CDN, and the second from our Node.js server (Socket.IO takes care of setting this up for you automatically). Insert these two lines in the head section of your page:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

<script src="http://localhost:8000/socket.io/socket.io.js"></script>

We’re now ready to connect to Node.js from this page and start listening to and processing messages. Add the following code to your head section:

<script>

var socket = io.connect('localhost', { port: 8000 });



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(56007)
What's Done in Darkness by Kayla Perrin(26587)
The Fifty Shades Trilogy & Grey by E L James(19075)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19054)
Shot Through the Heart by Mercy Celeste(18933)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17106)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(16974)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(16866)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16813)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16439)
The Subtle Art of Not Giving a F*ck by Mark Manson(14349)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14126)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13611)
Scorched Earth by Nick Kyme(12764)
Drei Generationen auf dem Jakobsweg by Stein Pia(10961)
Suna by Ziefle Pia(10886)
Scythe by Neal Shusterman(10332)
International Relations from the Global South; Worlds of Difference; First Edition by Arlene B. Tickner & Karen Smith(9517)
Successful Proposal Strategies for Small Businesses: Using Knowledge Management ot Win Govenment, Private Sector, and International Contracts 3rd Edition by Robert Frey(9361)
This is Going to Hurt by Adam Kay(9167)